<template>
    <view class="content" >
      <uniPopup background-color="rgba(255,255,255,0)" ref="inputDialog"  type="dialog" >
        <div class="mboxContent">
          <div class="main">
            <div class="mainText">导出成功</div>
            <div class="explain">{{ titles }}</div>
          </div>
        
         
          <div class="btn">
            <div class="fail btnItem" @click="toClose">返回</div>
            <div class="success btnItem" @click="goShare" >微信分享</div>
  
          </div>
        </div>
          
              </uniPopup>
              <div class="imgFix" v-if="isShow">
                <div class="imgFixMeng">
                  <div class="bgIncons">
                    <img src="../static/img/loadin.gif" alt="" class="imgFixImg">

                  </div>

                </div>
              </div>
    </view>
  </template>
  
  <script>
    import { IMG_URL} from "@/utils/config";
    import uniPopup from "@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue";

  export default {
    components:{
      uniPopup
    },
    props: {
      titles: {
        type: String,
      },
      isOpen: {
        type: Boolean,
      },
      urls: {
        type: String,
      },
    },
    data() {
      return {
        title: "",
        isShow:false
      };
    },
  
    onLoad() {},
    methods: {
      
      toClose(){
        this.$emit('closeAll',true)
        this.$refs.inputDialog.close()
      },
      mkdir(url){
    return new Promise(function(resolve, reject) {
      let fm = wx.getFileSystemManager();
      fm.mkdir({
        dirPath: wx.env.USER_DATA_PATH + "/images",
        recursive: true,
        success: function(res) {
          resolve();
        },
        fail: function(err) {
          resolve(err);
        }
      });
    });
  },
      goShare() {
        this.isShow =true
        var that =this
        let filePath = wx.env.USER_DATA_PATH + "/" + that.urls;
					uni.downloadFile({
					     url: IMG_URL+that.urls,
               header: {
          token: uni.getStorageSync("token"),
        },
               filePath:filePath,
					     success: (res) => {
					      uni.shareFileMessage({
					       filePath: res.filePath,
                 success:(b)=>{
              that.isShow=false

                  that.toClose()
                 },
                 fail:(c)=>{
                  uni.showToast({
								title:'分享失败',
								duration:1500
							})
              that.isShow=false
                 }
					      })
					    },
              fail:(a)=>{
                that.mkdir().then(res=>{
                  uni.downloadFile({
					     url: IMG_URL+that.urls,
               header: {
          token: uni.getStorageSync("token"),
        },
               filePath:filePath,
					     success: (res) => {
					      uni.shareFileMessage({
					       filePath: res.filePath,
                 success:(b)=>{
                  that.toClose()
                 },
                 fail:(c)=>{
          uni.showToast({
								title:'分享失败',
								duration:1500
							})
              that.isShow=false

                 }
					      })
					    },
              fail:(a)=>{
                console.log(a,'fila')
              that.isShow=false

              
              }
					})

                }).finally((res)=>{
                  console.log(res,'finally')
              that.isShow=false

                })
              }
					})
				}
			},

     
  };
  </script>
  
  <style scoped >
  
  .mboxContent{
    text-align: center;
   
    background: white;
    box-sizing: content-box;
    /* padding:24px; */
    width: 540rpx;
    border-radius: 20px;
  
  }
  .main{
    min-height: 274rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
  }
  .mainText{
    font-family: Source Han Sans CN, Source Han Sans CN;
  font-weight: bold;
  font-size: 34rpx;
  color: #262626;
  font-style: normal;
  }
  .rightimg{
width: 145rpx;
height: 121rpx;
margin:0 auto 32rpx
  }
  .btn{
    width: 100%;
    display: flex;
    box-sizing: border-box;
    padding:18rpx 0;
  display: flex;
  border-top: 2rpx solid #CBCBCB;
  }
  .fail{
    position: relative;
  
  }
  .fail::before{
    content: '';
    position: absolute;
    display: inline-block;
    width: 2rpx;
    background:  #CBCBCB;
    height: 86rpx;
      top: -20rpx;
      right: 0;
      overflow: hidden;
  }
  .btnItem{
    text-align: center;
      width: 49%;
      font-family: Source Han Sans CN, Source Han Sans CN;
  font-weight: bold;
  font-size: 32rpx;
  color: #0098C9;
  font-style: normal;
    }
  
  .imgFix{
    position: fixed;
    top:0;
    bottom: 0;
    left: 0;
    right: 0;

    z-index:99;
  }
  .bgIncons{
    width: 540rpx;
    height: 362rpx;
    position: absolute;
    top: 50%;
    left: 50%;
    background: white;
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    transform: translate(-50%,-50%);
    align-items: center;
    justify-content: center;
    display: flex;

  }
  .imgFixMeng{
    width:100%;
    height: 100%;
    position: relative;
    background: rgba(0,0,0,0.3)
  }
  .imgFixImg{
    /* position: absolute; */
    /* top: 50%;
    left: 50%;*/
    width: 342rpx;
    height: 228rpx; 

  }
  </style>
  